<?php

namespace app\Api\controller;


use think\Db;
use think\Request;


class Oauth extends \think\Controller
{
    public function _initialize()
    {



    }







    public function getwxinfo(){
        if(!$_GET['code']){ die;}
        $oauth = & load_wechat('Oauth');
        $ak= $oauth->getOauthAccessToken();
        $res=$oauth->getOauthUserinfo($ak['access_token'], $ak['openid']);

        $user['wxid']=$res['openid'];
        $user['nickname']=$res['nickname'];
        $user['pic']=$res['headimgurl'];
        session('wxid',$res['openid']);
        session('wxpic',$res['headimgurl']);
        session('nickname',$res['nickname']);
        session('user',$user);

        /*

        $user=Db::table('user')->where(['wxid'=>$res['openid']])->find();

        if($user){

            session('uid',$user['ID']);


        }else{


            $s['nickname']=$res['nickname'];
            $s['wxid']=$res['openid'];
            $s['pic']=$res['headimgurl'];
            $s['addtime']=date('Y-m-d H:i:s');

            $uid=Db::table('user')->insertGetId($s);

            session('uid',$uid);





        }



              */



        $this->redirect(session('burl'),302);


    }


}

